package com.qingke.pms.factory;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

import com.qingke.pms.command.Command;
import com.qingke.pms.pojo.Project;
import com.qingke.pms.pojo.User;

public class ProjectCommandFactory extends UserCommandFactory {
	private static Map<CommandCode,Class<? extends Command>> shopMap=new HashMap<>();
	static{
//		shopMap.put(CommandCode.ADD, AddToShoppingCartCommand.class);
//		shopMap.put(CommandCode.DELETE, DeleteFromShoppingCartCommand.class);
//		shopMap.put(CommandCode.DELIVERY, DeliveryCommand.class);
//		shopMap.put(CommandCode.EMPTY, EmptyShoppingCartCommand.class);
//		shopMap.put(CommandCode.LEAVE, LeaveShopCommand.class);
//		shopMap.put(CommandCode.OFFSHELF, OffShelfCommand.class);
//		shopMap.put(CommandCode.ONSHELF, OnShelfCommand.class);
//		shopMap.put(CommandCode.ORDER, PlaceOrderCommand.class);
//		shopMap.put(CommandCode.STATUS, ShopStatusCommand.class);
//		shopMap.put(CommandCode.GOODS, ViewGoodsCommand.class);
//		shopMap.put(CommandCode.CART, ViewShoppingCartCommand.class);
//		shopMap.put(CommandCode.HELP, ShopHelpCommand.class);
//		shopMap.put(CommandCode.SETPRICE, SetPriceCommand.class);
	}
	
	private Project project=null;
	
	public ProjectCommandFactory(User user,Project project) {
		super(user);
		this.project=project;
	}
	
	
	public Project getProject() {
		return project;
	}


	@Override
	public Command buildCommand(CommandCode cmdCode) {
		Class<? extends Command> commandClass=null;
		commandClass=shopMap.get(cmdCode);
		if(commandClass==null)
			return super.buildCommand(cmdCode);
		
		Command command=null;
		try {
			command=commandClass.getConstructor(User.class,Project.class).newInstance(this.getUser(),this.getProject());
		} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
				| NoSuchMethodException | SecurityException e) {
			e.printStackTrace();
		}
		return command;
	}

}
